<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
    <link rel="stylesheet" href="/stylesheets/index.css">
  </head>
  <body>
    <% include header.ejs %>
    <script src="http://localhost:3001/socket.io/socket.io.js"></script>

    <% if(user){%>
      <input type="text" name="" onchange="say(event)" value="">
    <%} else{ %>
      <h4>若要聊天请先登陆！</h4>
    <% }%>
    <div class="list">

    </div>



    <script type="text/javascript">
      const socket = io.connect("localhost:3001");
      function say(event){
        socket.emit('say',event.target.value);
      }
      const listDOM = document.querySelector(".list");
      socket.on('newsay',word=>{
        console.log(word);
        const pDOM = document.createElement("p");
        pDOM.innerText = word;
        listDOM.appendChild(pDOM);
      });
    </script>

  </body>
</html>
